package com.mk.util;

import org.apache.commons.lang3.StringUtils;

import java.util.function.Consumer;

/**
 * @author mk.chen
 * @date 2018-8-29
 */
public class ConditionUtils {

    public static final ConditionUtils INSTANCE = new ConditionUtils();

    /**
     * 如果不是null，执行consumer
     *
     * @param value
     * @param consumer
     * @param <T>
     * @return
     */
    public <T> ConditionUtils acceptIfNotNull(T value, Consumer<T> consumer) {
        if (value != null) {
            consumer.accept(value);
        }
        return this;
    }

    /**
     * 判断某字符串是否 不为空且长度不为0且不由空白符(whitespace) 构成，执行consumer
     *
     * @param value
     * @param consumer
     * @return
     */
    public ConditionUtils acceptIfNotBlank(String value, Consumer<String> consumer) {
        if (StringUtils.isNotBlank(value)) {
            consumer.accept(value);
        }
        return this;
    }
}
